package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

/**
 * 获取连接工具类
 */
public class ConUtils {

    /**
     * 获取连接
     */
    public static void getCon() {
        String url = "jdbc:avatica:remote:url=http://192.168.1.102:8888/druid/v2/sql/avatica/";
        Properties connectionProperties = new Properties();

        String sqlStr = "select user,count(user) as total from wikipedia group by user";
        try {
            Connection connection = DriverManager.getConnection(url,connectionProperties);
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sqlStr);
            while (resultSet.next()) {
                //System.out.println(" druid rs is " + resultSet.getObject(1));
                System.out.println("" + resultSet.getObject("user") + resultSet.getObject(1));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ConUtils.getCon();
    }

}
